package com.gopay.common.domain.view.config;

import com.gopay.common.util.compare.Compare;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ViewSolutionTransView extends View{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String intTxnCd;
	@Compare(columnName = "默认支付客户类型")
	private String defalutPayUserType;
	@Compare(columnName = "默认支付标签顺序")
	private List<ViewSolutionPaychannelTab> tabs;

    private  String prodCode; //账户产品代码

	
    public String getIntTxnCd() {
        return intTxnCd;
    }
    public void setIntTxnCd(String intTxnCd) {
        this.intTxnCd = intTxnCd;
    }
    public String getDefalutPayUserType() {
        return defalutPayUserType;
    }
    public void setDefalutPayUserType(String defalutPayUserType) {
        this.defalutPayUserType = defalutPayUserType;
    }
    public List<ViewSolutionPaychannelTab> getTabs() {
        return tabs;
    }
    public void setTabs(List<ViewSolutionPaychannelTab> tabs) {
        this.tabs = tabs;
    }

    public String getProdCode() {
        return prodCode;
    }

    public void setProdCode(String prodCode) {
        this.prodCode = prodCode;
    }

    public static Boolean tabsEquals(List<ViewSolutionPaychannelTab> tabsBefore, List<ViewSolutionPaychannelTab> tabsAfter){
        if(tabsBefore != null && tabsAfter != null){
            if(tabsBefore.size() == tabsAfter.size()){
                List<ViewSolutionPaychannelTab> compareBefore = new ArrayList<>();
                compareBefore.addAll(tabsBefore);
                List<ViewSolutionPaychannelTab> compareAfter = new ArrayList<>();
                compareAfter.addAll(tabsAfter);
                Comparator<ViewSolutionPaychannelTab> comparator = new Comparator<ViewSolutionPaychannelTab>() {
                    @Override
                    public int compare(ViewSolutionPaychannelTab o1, ViewSolutionPaychannelTab o2) {
                        if (o1 == null) {
                            return -1;
                        }
                        if (o2 == null) {
                            return 1;
                        }
                        if (o1.getOrder() == null) {
                            return -1;
                        }
                        if (o2.getOrder() == null) {
                            return 1;
                        }
                        return o1.getOrder().compareTo(o2.getOrder());
                    }
                };
                Collections.sort(compareBefore, comparator);
                Collections.sort(compareAfter, comparator);
                for(int i = 0 ; i < compareBefore.size() ; i++){
                    if(compareBefore.get(i) != null && compareAfter.get(i) != null){
                        if(compareBefore.get(i).getPayChannelId() != null){
                            if(!compareBefore.get(i).getPayChannelId().equals(compareAfter.get(i).getPayChannelId())){
                                return false;
                            }
                        }
                    } else if(compareBefore.get(i) == null){
                        if(compareAfter.get(i) != null){
                            return false;
                        }
                    } else {
                        return false;
                    }
                }
                return true;
            }
        } else if(tabsBefore == null ){
            if(tabsAfter == null || tabsAfter.size() == 0){
                return true;
            }
        } else if(tabsBefore.size() == 0) {
            return true;
        }
        return false;
    }

    public static String tabsTranslate(List<ViewSolutionPaychannelTab> tabs){
        StringBuilder sb = new StringBuilder();
        if(tabs != null){
            for(ViewSolutionPaychannelTab tab : tabs){
                if(tab != null && tab.getPayChannelDesc() != null){
                    sb.append(tab.getPayChannelDesc()).append("，");
                }
            }
        }
        if(sb.length() > 0){
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.toString();
    }

    public static String defalutPayUserTypeTranslate(String defalutPayUserType){
        if("01".equals(defalutPayUserType)){
            return "个人";
        } else if("02".equals(defalutPayUserType)){
            return "企业";
        }
        return "";
    }
}